﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonExtensions.ObjectExtensions;
using CommonExtensions.StringExtensions;
using DBMigrator.Core.DbObjects.Column;
using DBMigrator.Core.DbObjects.ForeignKey;

namespace DBMigrator.Core.DbObjects.Table
{
    public class AlterTable : Table, IAlterTable
    {
        public override Type SqlGenerationType
        {
            get { return typeof(IAlterTable); }
        }

        public AlterTable(string name)
            : base(name)
        {}

        public IChangeColumn ChangeColumn(string name)
        {
            if (name.IsBlank())
                throw new ArgumentNullException("name");

            var column = new ChangeColumn(name);
            Changes.Add(column);
            return column;
        }

        public IAlterTable DropColumn(string name)
        {
            if(name.IsBlank())
                throw new ArgumentNullException("name");

            Changes.Add(new DropColumn(name));
            return this;
        }

        public IAlterTable DropForeignKey(string name)
        {
            if (name.IsBlank())
                throw new ArgumentNullException("name");

            Changes.Add(new DropForeignKey(name));
            return this;
        }
    }
}
